package com.youxue.teachin.common.vo;

import android.os.Parcel;
import android.os.Parcelable;
import com.library.uiframework.utils.StringUtils;

/**
 * 在此写用途
 *
 * @author: zhiwei
 * @date: 2017-10-05 15:54
 * @version: 9.1.0
 */
public class UserVO implements Parcelable {
    /**
     * id : 18
     * ctime : 2017-10-05 07:53:01
     * utime : null
     * createdBy : null
     * username : null
     * realname : null
     * nickname : null
     * avatar : null
     * phone : 18501714348
     * email : null
     * sex : 0
     * classes : 0
     * locked : 0
     * studyStagesId : null
     * studySubjectId : null
     * lastLoginTime : null
     * lastLoginIp : null
     * isEmailConfirmed : 0
     * isPhoneConfirmed : 1
     * registerSource : 1
     * registerDevice : 0
     * registerApp : 0
     * qq : null
     * isQqConfirmed : 0
     * weibo : null
     * isWeiboConfirmed : 0
     * weixin : null
     * isWeixinConfirmed : 0
     * role : null
     * unionid : null
     * webLoginOpenId : null
     * miniOpenid : null
     */

    public int id;
    public String username;
    public String realname;
    public String nickname;
    /**
     * 介绍
     */
    public String introduce;
    public String avatar;
    public String phone;
    public String email;
    public String area;
    public int sex;
    public int classes;
    public int locked;
    public String studyStagesId = "";
    public String studyStagesName = "";
    public String studySubjectId = "";
    public String studySubjectName = "";

    public String lastLoginTime;
    public String lastLoginIp;
    public int isEmailConfirmed;
    public int isPhoneConfirmed;
    public int registerSource;
    public int registerDevice;
    public int registerApp;
    public String qq;
    /**
     * (0:未绑定;1:已绑定)
     */
    public int isQqConfirmed;
    public String weibo;
    public int isWeiboConfirmed;
    public String weixin;
    public int isWeixinConfirmed;
    public String role;
    public String unionid;
    public String webLoginOpenId;
    public String miniOpenid;

    private String mName ;
    public String getUsername() {
        if (mName != null) {
            return mName;
        }
        if (StringUtils.isNotEmpty(username)) {
            mName = username;
        } else if(StringUtils.isNotEmpty(realname)){
            mName = realname;
        } else if (StringUtils.isNotEmpty(nickname)) {
            mName = nickname;
        }

        return mName;
    }

    @Override
    public int describeContents() { return 0; }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.username);
        dest.writeString(this.realname);
        dest.writeString(this.nickname);
        dest.writeString(this.avatar);
        dest.writeString(this.phone);
        dest.writeString(this.email);
        dest.writeString(this.area);
        dest.writeInt(this.sex);
        dest.writeInt(this.classes);
        dest.writeInt(this.locked);
        dest.writeString(this.studyStagesId);
        dest.writeString(this.studySubjectId);
        dest.writeString(this.lastLoginTime);
        dest.writeString(this.lastLoginIp);
        dest.writeInt(this.isEmailConfirmed);
        dest.writeInt(this.isPhoneConfirmed);
        dest.writeInt(this.registerSource);
        dest.writeInt(this.registerDevice);
        dest.writeInt(this.registerApp);
        dest.writeString(this.qq);
        dest.writeInt(this.isQqConfirmed);
        dest.writeString(this.weibo);
        dest.writeInt(this.isWeiboConfirmed);
        dest.writeString(this.weixin);
        dest.writeInt(this.isWeixinConfirmed);
        dest.writeString(this.role);
        dest.writeString(this.unionid);
        dest.writeString(this.webLoginOpenId);
        dest.writeString(this.miniOpenid);
        dest.writeString(this.mName);
    }

    public UserVO() {}

    protected UserVO(Parcel in) {
        this.id = in.readInt();
        this.username = in.readString();
        this.realname = in.readString();
        this.nickname = in.readString();
        this.avatar = in.readString();
        this.phone = in.readString();
        this.email = in.readString();
        this.area = in.readString();
        this.sex = in.readInt();
        this.classes = in.readInt();
        this.locked = in.readInt();
        this.studyStagesId = in.readString();
        this.studySubjectId = in.readString();
        this.lastLoginTime = in.readString();
        this.lastLoginIp = in.readString();
        this.isEmailConfirmed = in.readInt();
        this.isPhoneConfirmed = in.readInt();
        this.registerSource = in.readInt();
        this.registerDevice = in.readInt();
        this.registerApp = in.readInt();
        this.qq = in.readString();
        this.isQqConfirmed = in.readInt();
        this.weibo = in.readString();
        this.isWeiboConfirmed = in.readInt();
        this.weixin = in.readString();
        this.isWeixinConfirmed = in.readInt();
        this.role = in.readString();
        this.unionid = in.readString();
        this.webLoginOpenId = in.readString();
        this.miniOpenid = in.readString();
        this.mName = in.readString();
    }

    public static final Creator<UserVO> CREATOR = new Creator<UserVO>() {
        @Override
        public UserVO createFromParcel(Parcel source) {return new UserVO(source);}

        @Override
        public UserVO[] newArray(int size) {return new UserVO[size];}
    };
}
